<?php

namespace App\Http\Requests\Api;

use Illuminate\Validation\Rule;

class RegisterRequest extends BaseRequest
{

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            'username'=>'required|min:3|max:20|unique:user,username|string|regex:/[A-Za-z0-9_]$/',
            'password'=>'required|min:3|max:16|string',
            'tel'=>'required|integer|regex:/^1[3456789]\d{9}$/|unique:user,tel',
            'email'=>'required|unique:user,email|email|regex:/^[A-Za-z0-9\u4e00-\u9fa5]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/',
			'age'=>'nullable|integer|min:10|max:125',
			'sex'=>[
				'nullable',
				Rule::in([1,0]),
			]
        ];
    }

	public function attributes()
    {
		return [
			'username'=>'用户名',
			'password'=>'密码',
			'tel'=>'手机号',
			'email'=>'邮箱',
			'age'=>'年龄',
			'sex'=>'性别',
		];
    }

	public function messages()
    {
		return [
			'username.regex'=>'用户名只能是数字，字母，下划线组成',
			'sex.in'=>'性别参数错误',
		];
    }
}
